package com.qingyun.system.controller;

import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.qingyun.system.common.result.Result;
import com.qingyun.system.service.ChatService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



@Slf4j
@RestController
@RequestMapping("/openai")
public class OpenAIController {

    @Resource
    private ChatService chatService;


    @Operation(summary = "聊天接口", description = "聊天接口")
    @GetMapping("/chat")
    public Result chat(@RequestParam(value = "content",required = true) String content) {
        GenerationResult result = chatService.callWithMessage(content);
        System.out.println(result);
        //String message = result.getOutput().getChoices().get(0).getMessage().getContent();
        String message = result.getOutput().getText();
        System.out.println(message);

        log.info("OpenAI聊天接口返回结果：{}", message);

        return Result.success(message);
    }

}
